using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;

namespace DAO
{
    public class DuLichDAO
    {
        #region 4. Retreiving
        public static List<DuLichDTO> SelectChuyenDuLichAndTenTuyenDuLichByThoiGianKhoiHanh(DateTime thoiGianKhoiHanh)
        {
            List<DuLichDTO> list = new List<DuLichDTO>();
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@ThoiGianKhoiHanh", thoiGianKhoiHanh));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("usp_SelectChuyenDuLichAndTenTuyenDLByThoiGianKhoiHanh", sqlParams);
                foreach (DataRow dr in dt.Rows)
                {
                    DuLichDTO duLich = new DuLichDTO();
                    duLich.MaChuyenDL = dr["MaChuyenDL"].ToString();
                    duLich.TenTuyenDL = dr["TenTuyenDL"].ToString();
                    duLich.ThoiGianKhoiHanh = DateTime.Parse(dr["ThoiGianKhoiHanh"].ToString());
                    duLich.TongThoiGian = double.Parse(dr["TongThoiGian"].ToString());
                    list.Add(duLich);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return list;
        }

        public static List<DuLichDTO> SelectChuyenDuLichAndTenTuyenDuLichByTenThanhPho(String tenThanhPho)
        {
            List<DuLichDTO> list = new List<DuLichDTO>();
            try
            {
                // Create List Sql Parameter
                List<SqlParameter> sqlParams = new List<SqlParameter>();
                sqlParams.Add(new SqlParameter("@TenThanhPho", tenThanhPho));
                DataTable dt = SqlDataAccessHelper.ExecuteQuery("usp_SelectChuyenDuLichAndTenTuyenDLByTenThanhPho", sqlParams);
                foreach (DataRow dr in dt.Rows)
                {
                    DuLichDTO duLich = new DuLichDTO();
                    duLich.TenThanhPho = dr["TenThanhPho"].ToString();
                    duLich.MaChuyenDL = dr["MaChuyenDL"].ToString();
                    duLich.TenTuyenDL = dr["TenTuyenDL"].ToString();
                    duLich.ThoiGianKhoiHanh = DateTime.Parse(dr["ThoiGianKhoiHanh"].ToString());
                    duLich.TongThoiGian = double.Parse(dr["TongThoiGian"].ToString());
                    list.Add(duLich);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return list;
        }
        #endregion 
    }
}
